/*
 * @Date: 2022-04-12 11:12:32
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-04-14 14:49:50
 * @FilePath: \weibovue\src\utils\tools.ts
 * @Description: 工具函数
 */
//日期格式转换
export const DateFormat = (time: number | string) => {
  let date = new Date(time).getTime();
  let JoinDate = new Date(date);
  let y = JoinDate.getFullYear();
  let m = ("0" + (JoinDate.getMonth() + 1)).slice(-2);
  let d = ("0" + JoinDate.getDate()).slice(-2);
  return `${y}-${m}-${d}`;
};
//发布时间
export const createTime = (time: number | string) => {
  let nowDate = Date.now();
  let date = new Date(time);
  let crTime = date.getTime();
  let y = date.getFullYear();
  let m = ("0" + (date.getMonth() + 1)).slice(-2);
  let d = ("0" + date.getDate()).slice(-2);
  let h = Math.floor((nowDate - crTime) / 1000 / 60 / 60);
  let mintes = Math.floor((nowDate - crTime) / 1000 / 60);
  if (h > 24 && h < 48) {
    return `昨天`;
  } else if (h > 48 && h < 72) {
    return `两天前`;
  } else if (h > 72) {
    return `${y}-${m}-${d}`;
  } else {
    if (mintes > 60) {
      return h;
    } else {
      return `${mintes}分钟前`;
    }
  }
};
